<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>设置</title>
		<link href="../../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../../css/app.css" />
	</head>

	<body id="app">
			<header class="mui-bar mui-bar-nav">
				<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"><span>返回</span></a>
				<h1 class="mui-title" id="title">设置</h1>
			</header>
			<div class="mui-content">
				<ul class="mui-table-view">
					<li class="mui-table-view-cell">
								不允许陌生人私信
								<div @toggle="toggleMsg" :class="'mui-switch mui-switch-mini'+(msg=='1'?' mui-active':'')">
									<div class="mui-switch-handle"></div>
								</div>
							</li>
							<li class="mui-table-view-divider">开启后，未相互关注的用户将不可以私信你</li>
				</ul>
				<ul class="mui-table-view" style="margin-top: 15px;">
					<li class="mui-table-view-cell">
								发表话题不更新动态
								<div @toggle="toggleTrend" :class="'mui-switch mui-switch-mini'+(trendmsg=='1'?' mui-active':'')">
									<div class="mui-switch-handle"></div>
								</div>
							</li>
							<li class="mui-table-view-divider">开启后，你发表的话题将不显示在个人动态中</li>
				</ul>
				<ul class="mui-table-view" style="margin-top: 15px;">
					<li class="mui-table-view-cell">
						<a @tap='changepwd' id="modifyPassword" class="mui-navigate-right">
							修改密码
						</a>
					</li>
				</ul>
				<ul class="mui-table-view" style="margin-top: 15px;">
					<li class="mui-table-view-cell">
						<a @tap='logout' class="mui-navigate-right">
							退出登录
						</a>
					</li>
				</ul>
			</div>
		</div>
		<script src="../../js/mui.min.js"></script>
		<script src="../../js/mui-extend.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/vue.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/app.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript" charset="utf-8">
			mui.init();
			var uinfo = persistent.uinfo();
			var vm = new Vue({
				el:'#app',
				data:{
					msg:uinfo.SettingsMsg,
					trend:uinfo.SettingsTrend,
				},
				ready:function () {
					mui.plusReady(function() {
						var current = plus.webview.currentWebview();
						showPage(current);
					});
				},
				methods:{
					toggleMsg:function(){
						console.log("私信触发");
						var self = this;
						var uinfo = persistent.uinfo();
						if(uinfo.SettingsMsg == '0') {
							value='1';
						} else {
							value='0';
						}
						user.updateuserinfo('Pletter', value, function(data) {
							//console.log(data);
							if (data == 200) {
								//修改成功更新缓存
								var uinfo = persistent.uinfo();
								uinfo['SettingsMsg'] = value
								cache('uinfo', JSON.stringify(uinfo));
								this.msg = value;
							} else {
								mui.toast("Error:");
							}
						});
					},
					toggleTrend:function(){
						console.log("动态触发");
						var self = this;
						var uinfo = persistent.uinfo();
						if(uinfo.SettingsTrend == '0') {
							value='1';
						} else {
							value='0';
						}
						user.updateuserinfo('Syns_dynamic', value, function(data) {
							//console.log(data);
							if (data == 200) {
								//修改成功更新缓存
								var uinfo = persistent.uinfo();
								uinfo['SettingsTrend'] = value
								cache('uinfo', JSON.stringify(uinfo));
								this.trend = value;
							} else {
								mui.toast("Error:");
							}
						});
					},
					changepwd:function(){
						mui.plusReady(function() {
							openPage('../mycenter/changePwd.html','changePwd');
						});
					},
					logout:function () {
						var btnArray = ['是', '否'];
						mui.confirm('确定要退出吗？', '学园', btnArray, function(e) {
							if (e.index == 0) {
								// 同意退出
								var Username = persistent.uinfo().Telephone;
								cache("uid",null);
								cache("utoken",null);
								cache("uinfo",null);
								cache('lastUser', Username);
								mui.fire(plus.webview.getLaunchWebview(), 'relogin');
							} else {
								return;
							}
						})
					}
				}
			})
			
		</script>
	</body>
</html>